//
//  CZStatusForwardCell.m
//  XinLang_OC
//
//  Created by WONG on 16/3/16.
//  Copyright © 2016年 cheuhui. All rights reserved.
//

#import "CZStatusForwardCell.h"
#import "CZStatus.h"
#import "CZUser.h"
#import "CZStatusBottomView.h"
#import "CZPictureView.h"


@interface CZStatusForwardCell ()

/**
 * 显示被转发微博的内容
 */
@property (nonatomic,strong) UILabel *forwardLabel;
/**
 *  背景 按钮
 */
@property (nonatomic,strong) UIButton *bkgButton;


@end

@implementation CZStatusForwardCell

- (void)setStatus:(CZStatus *)status {
    [super setStatus:status];
    
    NSString *name = status.retweeted_status.user.screen_name;
    if (!name) {
        name = @"被转发的微博名称为空";
    }
    NSString *retweetText = status.retweeted_status.text;
    if (!retweetText) {
        retweetText = @"被转发微博内容为空";
    }
    self.forwardLabel.text = [NSString stringWithFormat:@"@%@:%@",name,retweetText];
    
    // self.pictureView.status 要转发微博的数据了
    self.pictureView.status = self.status.retweeted_status;
    self.size = [self.pictureView calcViewSize];
    /*
     更新约束
     */
    [self.pictureView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(self.size);
        make.left.equalTo(self).offset(8);
        make.top.equalTo(self.forwardLabel.mas_bottom).offset(8);
    }];

}

// 覆盖父类的方法
- (void)prepareUI {
    [super prepareUI];
    // 添加子类自己特有的空间, 0是插入到最底部
    [self.contentView insertSubview:self.bkgButton atIndex:0];
    [self.contentView addSubview:self.forwardLabel];
    
    /*
        添加约束
    */
    // 背景按钮
    [self.bkgButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
        make.top.equalTo(self.contentLabel.mas_bottom);
        make.bottom.equalTo(self.bottomView.mas_top);
    }];
    
    [self.forwardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bkgButton.mas_top).offset(8);
        make.left.equalTo(self.bkgButton.mas_left).offset(8);
        make.right.equalTo(self.bkgButton.mas_right).offset(-8);
    }];
    
    // 拿到配图数据，计算size，重新更新约束
    [self.pictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(200, 200));
        make.left.equalTo(self).offset(8);
        make.top.equalTo(self.forwardLabel.mas_bottom).offset(8);
    }];
}


#pragma mark - lazy load

- (UIButton *)bkgButton {
    if (!_bkgButton) {
        _bkgButton = [[UIButton alloc] init];
        _bkgButton.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
    }
    return _bkgButton;
}
- (UILabel *)forwardLabel {
    if (!_forwardLabel) {
        _forwardLabel = [[UILabel alloc] init];
        _forwardLabel.font = [UIFont systemFontOfSize:14];
        _forwardLabel.numberOfLines = 0;
        [_forwardLabel sizeToFit];
    }
    return _forwardLabel;
}


@end












